import { Component } from '@angular/core';
import { Stop } from '../../trip/stop/stop';

import { OnInit } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';

import { StopService } from '../../trip/stop/stop.service';

@Component({
  selector: 'my-stoptripdriver',
  templateUrl: './stoptripdriver.component.html',
})

export class StoptripdriverComponent implements OnInit {
  trip_id: number;
  ngOnInit() {
    this.router.queryParams.forEach((params: Params) => {
      this.trip_id = +params['trip_id'];
      console.log(this.trip_id);
      this.stopService.getStops(this.trip_id).then(stops => this.stops = stops);
    });
  }

  stops: Stop[];
  selectedStop: Stop;

  onSelect(stop: Stop) { this.selectedStop = stop; }
  onNew() {
      this.selectedStop = new Stop();
      this.selectedStop.trip_id = this.trip_id;
    };

  constructor(
    private router: ActivatedRoute,
    private stopService: StopService) {
  }

  getStops() {
    this.stopService.getStops(this.trip_id).then(stops => this.stops = stops);
  }
}
